package com.sfpay.coreplatform.member.service.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.sfpay.coreplatform.account.valueobject.dto.OpenAcc;
import com.sfpay.coreplatform.account.valueobject.dto.OpenAccReturn;
import com.sfpay.coreplatform.member.common.MemberResponseCode;
import com.sfpay.coreplatform.member.common.constant.Constants;
import com.sfpay.coreplatform.member.common.enums.AcctUseFlag;
import com.sfpay.coreplatform.member.common.enums.ChannelCode;
import com.sfpay.coreplatform.member.common.enums.DealerFlag;
import com.sfpay.coreplatform.member.common.enums.EPCertType;
import com.sfpay.coreplatform.member.common.enums.MemberLockStatus;
import com.sfpay.coreplatform.member.common.enums.MemberStatus;
import com.sfpay.coreplatform.member.common.enums.MemberType;
import com.sfpay.coreplatform.member.common.enums.OperatorStatus;
import com.sfpay.coreplatform.member.common.enums.SafeFlag;
import com.sfpay.coreplatform.member.common.util.AccountUtil;
import com.sfpay.coreplatform.member.common.util.EncryptUtil;
import com.sfpay.coreplatform.member.common.util.StringUtil;
import com.sfpay.coreplatform.member.persistence.dao.IEnterpriseManageDao;
import com.sfpay.coreplatform.member.persistence.dao.IMemberAccountManageDao;
import com.sfpay.coreplatform.member.persistence.dao.IMemberManageDao;
import com.sfpay.coreplatform.member.persistence.dao.IOperatorManagerDao;
import com.sfpay.coreplatform.member.service.IEnterpriseService;
import com.sfpay.coreplatform.member.service.exception.MemberServiceException;
import com.sfpay.coreplatform.member.service.inner.IMemberHelpService;
import com.sfpay.coreplatform.member.service.proxy.account.IAcctProxyManageService;
import com.sfpay.coreplatform.member.service.validate.BussineValidate;
import com.sfpay.coreplatform.member.service.validate.ValidateUtil;
import com.sfpay.coreplatform.member.valueobject.dto.EnterpriseMember;
import com.sfpay.coreplatform.member.valueobject.dto.Member;
import com.sfpay.coreplatform.member.valueobject.dto.MemberAccount;
import com.sfpay.coreplatform.member.valueobject.dto.MemberOperator;
import com.sfpay.coreplatform.member.valueobject.tmo.MemberInfo;
import com.sfpay.coreplatform.member.valueobject.tmo.OperatorInfo;


@Service
public class EnterpriseServiceImpl implements IEnterpriseService {

	private final static Logger logger = LoggerFactory.getLogger(EnterpriseServiceImpl.class);
	
	@Resource
	private IMemberManageDao memberManageDao;
	
	@Resource
	private IOperatorManagerDao operatorManagerDao;
	
	@Resource
	private IEnterpriseManageDao enterpriseManageDao;
	
	@Resource
	private IMemberAccountManageDao memberAccountManageDao;
	
	@Resource
	private IMemberHelpService memberHelpService;
	
	@Resource
	private IAcctProxyManageService acctProxyManageService;
	
	@Override
	@Transactional(rollbackFor= MemberServiceException.class,propagation=Propagation.REQUIRED)
	public void updateLoginPwd(String loginId, String oldPwd, String newPwd,
			int loginType, MemberType memberType) throws MemberServiceException
	{
		if (logger.isDebugEnabled()) 
		{
			logger.debug("method:updateLoginPwd,update loginpwd for comp member,the parameters 's info"
					+ "{loginId:" + loginId + ",oldPwd:" + oldPwd + ",newPwd:"+ newPwd 
					+ ",loginType:" + loginType + ",memberType:" + memberType +"}");
		}
		
		// 校验参数信息
		ValidateUtil.checkLoginType(loginId, loginType);
		ValidateUtil.checkParamIsNull(oldPwd, "oldPwd");
		ValidateUtil.checkParamIsNull(newPwd, "newPwd");
		if (oldPwd.equals(newPwd))
		{
			throw new MemberServiceException(MemberResponseCode.INVALID_PWD,"new password can not same as old password");
		}
		else if(memberType == null || MemberType.COMP != memberType)
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ERR_FORMAT,
					"memberType must be 'COMP'");
		}

		// 根据标示查询当前会员信息
		Member member = null;
		try 
		{
			member = memberManageDao.queryPersonBaseInfoByType(loginId,loginType,memberType);
			BussineValidate.checkMemberStatus(member);
			//比较旧密码是否正确
			if (!member.getPwd().equals(EncryptUtil.encryptPwd(oldPwd))) 
			{
				throw new MemberServiceException(MemberResponseCode.INVALID_PWD,"old password does not match");
			}
			//更新操作员密码
			int counts = operatorManagerDao.updateOperatorLoginPwd(member.getMobile(), member.getEmail(),
					member.getLoginName(),memberType, member.getPwd(), EncryptUtil.encryptPwd(newPwd));
			if(counts != 1)
			{
				throw new MemberServiceException(MemberResponseCode.CAN_NOT_REPEAT_REQUEST,"can not repeat request");
			}
		}
		catch (Exception e) 
		{
			logger.error("method:updateLoginPwd,update loginpwd for person member error", e);
			if(SQLException.class.isInstance(e.getCause()))
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"" + ((SQLException)(e.getCause())).getErrorCode(),e);
			}
			throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"update data occur exception", e);
		}
		if (logger.isDebugEnabled()) 
		{
			logger.debug("method:updateLoginPwd,update loginpwd for person member successful,the parameters 's info"
					+ "{loginId:" + loginId + ",oldPwd:" + oldPwd + ",newPwd:"+ newPwd 
					+ ",loginType:" + loginType + ",memberType:" + memberType +"}");
		}
		
	}

	@Override
	@Transactional(rollbackFor= MemberServiceException.class,propagation=Propagation.REQUIRED)
	public void resetLoginPwd(String loginId, String newPwd,int loginType, MemberType memberType) 
			throws MemberServiceException 
	{
		if (logger.isDebugEnabled()) 
		{
			logger.debug("resetLoginPwd,resetloginpwd for person member,the parameters 's info"
					+ "{loginId:" + loginId + ",newPwd:"+ newPwd + ",loginType:" + loginType + ",memberType:" + memberType +"}");
		}
		
		// 校验参数信息
		ValidateUtil.checkLoginType(loginId, loginType);
		ValidateUtil.checkParamIsNull(newPwd, "newPwd");
		if(memberType == null || MemberType.COMP != memberType)
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ERR_FORMAT,
					"memberType must be COMP");
		}

		// 根据标示查询当前会员信息
		Member member = null;
		try 
		{
			member = memberManageDao.queryPersonBaseInfoByType(loginId,loginType,memberType);
			BussineValidate.checkMemberStatus(member);
			//重置操作员密码
			int counts = operatorManagerDao.updateOperatorLoginPwd(member.getMobile(), member.getEmail(),
					member.getLoginName(),memberType, member.getPwd(), EncryptUtil.encryptPwd(newPwd));
			if(counts != 1)
			{
				throw new MemberServiceException(MemberResponseCode.CAN_NOT_REPEAT_REQUEST,"can not repeat request");
			}
		}
		catch (Exception e) 
		{
			logger.error("resetLoginPwd,resetloginpwd for person member error", e);
			if(SQLException.class.isInstance(e.getCause()))
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"" + ((SQLException)(e.getCause())).getErrorCode(),e);
			}
			throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"update data occur exception", e);
		}
		
		if (logger.isDebugEnabled()) 
		{
			logger.debug("resetLoginPwd,resetloginpwd for COMP member success!,the parameters 's info"
					+ "{loginId:" + loginId + ",newPwd:"+ newPwd + ",loginType:" + loginType + ",memberType:" + memberType +"}");
		}
	}

	@Override
	@Transactional(rollbackFor= MemberServiceException.class,propagation=Propagation.REQUIRED)
	public long registerEnterpriseMember(EnterpriseMember enterpriseMember)	
			throws MemberServiceException
	{
		if(logger.isDebugEnabled())
		{
			logger.debug("method:registerEnterpriseMember,register Enterprise Member,the parameters 's info"+ 
					"{enterpriseMember:"+enterpriseMember+"}");
		}
		//必需参数校验
		validEnterpriseMemberReg(enterpriseMember);
		
		long memberNo = 0L;
		try
		{
			//验证企业的组织机构，营业执照(企业证件类型与证件号码)是否已经注册
			memberHelpService.queryEPMemberIsExist(enterpriseMember);
			
			//企业操作员手机，邮箱，登入名，证件+号码是否已经使用
			memberHelpService.queryOperatorIsExist(enterpriseMember);
			
			//注册会员
			memberNo = memberHelpService.generateMemberNo(enterpriseMember.getMemberType(), enterpriseMember.getChannel());
			
			MemberInfo memberInfo = new MemberInfo();
			memberInfo.setActive(enterpriseMember.getActive());
			memberInfo.setChannel(ChannelCode.valueOf(enterpriseMember.getChannel()));
			memberInfo.setDealerFlag(enterpriseMember.getDealerFlag() == null ? DealerFlag.GENERAL : enterpriseMember.getDealerFlag());//开户时候,默认普通会员
			memberInfo.setMemberName(enterpriseMember.getMemberName());
			memberInfo.setMemberNo(memberNo);
			memberInfo.setMemberSrc(enterpriseMember.getMemberSource());
			memberInfo.setActive(enterpriseMember.getActive());
			memberInfo.setMemberType(enterpriseMember.getMemberType());
			memberInfo.setNameAuthFlag(StringUtil.isStrNull(enterpriseMember.getNameAuthFlag())? "Y" : enterpriseMember.getNameAuthFlag());//N实名用户 Y非实名用户
			memberInfo.setSafeFlag(SafeFlag.BASIC);//开户默认初始状态
			 //开户默认NORMAL态
			memberInfo.setStatus(MemberStatus.NORMAL);
			memberInfo.setSysSource("PAY_SYS");
			memberInfo.setCertNo(enterpriseMember.getCertNo());
			memberInfo.setCertTypeCode(enterpriseMember.getCertType());
			memberInfo.setCertValidBeginDate(enterpriseMember.getCertValidBeginDate());
			memberInfo.setCertValidEndDate(enterpriseMember.getCertValidEndDate());
			memberManageDao.addMemberInfo(memberInfo);
			
			//添加企业扩展表信息
			
			enterpriseMember.setMemberNo(memberNo);
			enterpriseManageDao.addMemberEPExts(enterpriseMember);
			
			//插入操作员表
			OperatorInfo operatorInfo = new OperatorInfo();
			operatorInfo.setMemberNo(memberNo);
			operatorInfo.setMobile(enterpriseMember.getMobile());
			operatorInfo.setLoginName(enterpriseMember.getLoginName());
			operatorInfo.setOperatorType("C_MANAGE");
			operatorInfo.setPwd(EncryptUtil.encryptPwd(enterpriseMember.getPwd()));
			operatorInfo.setStatus(OperatorStatus.YCHECK); //个人默认是已审核状态
			operatorInfo.setTelephone(enterpriseMember.getOperTelephone());
			operatorManagerDao.addOperatorInfo(operatorInfo);
			//若是商户，这开通本金虚户(默认与会员登入密码一致)
			if(DealerFlag.DEALER == enterpriseMember.getDealerFlag())
			{
				//调用账户，添加虚户(第一步 账户未激活)
				OpenAcc openAcc = AccountUtil.addMemberVirtualAcc(memberNo, EncryptUtil.encryptPwd(enterpriseMember.getPwd()), Constants.ACCOUNT_TYPE_NO_FOR_101);
				OpenAccReturn openAccReturn = acctProxyManageService.openAccount(openAcc);
				
				//添加会员与账户映射关系
				MemberAccount memberAccount = new MemberAccount();
				memberAccount.setAccountNo(openAccReturn.getAccountNo());
				memberAccount.setMemberNo(openAccReturn.getMemberNo());
				memberAccount.setAccountType(Constants.ACCOUNT_TYPE_NO_FOR_101);
				memberAccount.setDefaultAcctFlag(Constants.COMM_Y);//是否资金账户
				memberAccount.setProductType("VA");//产品类型 虚拟卡
				memberAccount.setAcctUseFlag(AcctUseFlag.DEFAULT);
				memberAccount.setBussineProductType("VA");
				memberAccountManageDao.addMemberAccountInfo(memberAccount);
				
				//激活账户
				try
				{
					acctProxyManageService.makeAccountActive(openAccReturn.getAccountNo());
				}
				catch(Exception e)
				{
					logger.error("method:registerEnterpriseMember:makeAccountActive, active comp member's normal account active error", e);
				}
			}
		}
		catch(MemberServiceException e)
		{
			logger.error("method:registerEnterpriseMember,register Enterprise Member . error", e);
			throw e;
		}
		catch(Exception e)
		{
			logger.error("method:regeditEnterpriseMember,register Enterprise Member . error", e);
			if(SQLException.class.isInstance(e.getCause()))
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"" + ((SQLException)(e.getCause())).getErrorCode(),e);
			}
			throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"insert data occur exception",e);
		}
		
		if(logger.isDebugEnabled())
		{
			logger.debug("method:registerEnterpriseMember,register Enterprise Member successful!,the parameters 's info"+ 
					"{enterpriseMember:"+enterpriseMember+"}");
		}
		
		return memberNo;
	}

	private void validEnterpriseMemberReg(EnterpriseMember enterpriseMember) throws MemberServiceException
	{
		if(enterpriseMember == null)
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"parameter is null");
		}
		else
		{
			if(MemberType.COMP != enterpriseMember.getMemberType())
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ERR_FORMAT,"the Parameter member type must be 'COMP' ");
			}
			else if(StringUtil.isStrNull(enterpriseMember.getEpRegName()))
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"enterprise register 's Name is null or empty");
			}
			else if(enterpriseMember.getEpCertType() == null)
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"enterprise cert.Type is null");
			}
			else if(enterpriseMember.getEpCertType() == EPCertType.EP_OTHER && StringUtil.isStrNull(enterpriseMember.getEpCertTypeOther()))
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"the other certType must have value ," +
					"when enterprise register and enterprise certType is other");
			}
			else if(StringUtil.isStrNull(enterpriseMember.getEpCertNo()))
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"enterprise cert.No is null");
			}
			else if(StringUtil.isStrNull(enterpriseMember.getMobile()) 
					&& StringUtil.isStrNull(enterpriseMember.getEmail())
					&& StringUtil.isStrNull(enterpriseMember.getLoginName()))
			{
				throw new MemberServiceException(MemberResponseCode.INVALID_LEAST_ONE_VALUE,"the Parameter mobile, email, " +
						"login name at least a parameter value");
			}
		}
	}

	@Override
	@Transactional(rollbackFor= MemberServiceException.class,propagation=Propagation.REQUIRED)
	public void update(EnterpriseMember modifyInfo) throws MemberServiceException
	{
		if (logger.isDebugEnabled()) 
		{
			logger.debug("method:update,comp member update member's info,the parameters 's info"
					+ "{modifyInfo:" + modifyInfo + "}");
		}
		//参数校验
		validModifyCompMember(modifyInfo);
		
		try 
		{
			EnterpriseMember tmpMemberEx = enterpriseManageDao.queryEnterpriseMemberByMemberNo(modifyInfo.getMemberNo());
			//检查企业信息是否已经使用
			checkEpIsExists(modifyInfo, tmpMemberEx);
			
			//校验企业操作员信息是否已经使用
			Member midifyMember = new Member();
			midifyMember.setMemberType(MemberType.COMP);
			boolean modifyImportInfo = false;
			if (!StringUtil.isStrNull(modifyInfo.getMobile()) && !tmpMemberEx.getMobile().equals(modifyInfo.getMobile())) 
			{
				modifyImportInfo = true;
				midifyMember.setMobile(modifyInfo.getMobile());
			}
			if (!StringUtil.isStrNull(modifyInfo.getEmail()) && !tmpMemberEx.getEmail().equals(modifyInfo.getEmail()))
			{
				modifyImportInfo = true;
				midifyMember.setEmail(modifyInfo.getEmail());
			}
			if(!StringUtil.isStrNull(modifyInfo.getLoginName()) 
					&& !tmpMemberEx.getLoginName().equals(modifyInfo.getLoginName())) 
			 {
				 modifyImportInfo = true;
				 midifyMember.setLoginName(modifyInfo.getLoginName()); 
			 }
			
			//已经实名认证后，不能修改信息
			if(Constants.COMM_N.equals(tmpMemberEx.getNameAuthFlag()) && modifyImportInfo)
			{
				throw new MemberServiceException(MemberResponseCode.CANNOT_MODIFYINFO_AFTER_NAMEAUTH,"can not modify mobile,mail," +
						"loginName,certType,certNo after name auth");
			}
			 //校验修改后的会员（手机，邮箱，登入名，证件类型+证件号码）是否已经存在
			if(modifyImportInfo)
			{
				memberHelpService.queryOperatorIsExist(midifyMember);
			}
			
			//修改信息
			enterpriseManageDao.updateEPMemberExtInfo(modifyInfo);
			
			//修改会员主表内容
			MemberInfo memberInfo = new MemberInfo();
			memberInfo.setMemberNo(modifyInfo.getMemberNo());
			memberInfo.setMemberName(modifyInfo.getEpRegName());
			memberInfo.setCertTypeCode(modifyInfo.getAgentCertType());
			memberInfo.setCertNo(modifyInfo.getAgentnCertNo());
			memberInfo.setCertValidBeginDate(modifyInfo.getAgentCertBeginDate());
			memberInfo.setCertValidEndDate(modifyInfo.getAgentCertEndDate());
			//更新操作员表内容
			OperatorInfo operatorInfo = new OperatorInfo();
			operatorInfo.setCertNo(modifyInfo.getAgentnCertNo());
			operatorInfo.setCertTypeCode(modifyInfo.getAgentCertType());
			operatorInfo.setCertValidBeginDate(modifyInfo.getAgentCertBeginDate());
			operatorInfo.setCertValidEndDate(modifyInfo.getAgentCertEndDate());		
			operatorInfo.setEmail(modifyInfo.getAgentMail());
			operatorInfo.setMemberNo(modifyInfo.getMemberNo());
			operatorInfo.setMobile(modifyInfo.getAgentMobile());//设置发短信手机号	
			operatorInfo.setTelephone(modifyInfo.getAgentPhone());		
			
			//更新会员表
			memberManageDao.updateMemberInfoByMemberNo(memberInfo);
			
			//更新操作员表
			operatorManagerDao.updateEnterpriseOperator(operatorInfo,tmpMemberEx.getMemberNo(),tmpMemberEx.getMobile(),
					tmpMemberEx.getEmail(),tmpMemberEx.getLoginName());
		}
		catch(MemberServiceException e)
		{
			logger.error("method:update,comp member update enterprise member error",e);
			throw e;
		}
		catch (Exception e) 
		{
			logger.error("method:update,comp member update enterprise member error",e);
			if(SQLException.class.isInstance(e.getCause()))
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"" + ((SQLException)(e.getCause())).getErrorCode(),e);
			}
			throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, "update db occur exception", e);
		}
		
		if (logger.isDebugEnabled()) 
		{
			logger.debug("method:update,comp member update member's info successful!,the parameters 's info"
					+ "{modifyInfo:" + modifyInfo + "}");
		}
	}

	private void validModifyCompMember(EnterpriseMember modifyInfo)
			throws MemberServiceException
	{
		if(modifyInfo.getMemberNo() == null)
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"enterprise MemberNo os null");
		}
		if(StringUtil.isStrNull(modifyInfo.getEpRegName()))
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"enterprise register Name is null or empty");
		}
		else if(modifyInfo.getEpCertType() == null)
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"enterprise cert.Type is null or empty");
		}
		else if(modifyInfo.getEpCertType() == EPCertType.EP_OTHER && StringUtil.isStrNull(modifyInfo.getEpCertTypeOther()))
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"the other certType must have value ," +
					"when enterprise register and enterprise certType is other");
		}
		else if(StringUtil.isStrNull(modifyInfo.getEpCertNo()))
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"enterprise cert.No is null or empty ");
		}
		else if(StringUtil.isStrNull(modifyInfo.getAgentName()))
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"agent is null or empty");
		}
		else if(modifyInfo.getAgentCertType() == null)
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"agent cert.Type is null or empty");
		}
		else if(StringUtil.isStrNull(modifyInfo.getAgentnCertNo()))
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"agent cert.No is null or empty");
		}
		else if(StringUtil.isStrNull(modifyInfo.getAgentMobile()))
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL,"agent mobile is null or empty");
		}
	}

	@Override
	@Transactional(readOnly=true)
	public EnterpriseMember queryEnterpriseMemberByMbrNo(Long memberNo) throws MemberServiceException 
	{
		if (logger.isDebugEnabled()) 
		{
			logger.debug("method:queryEnterpriseMemberByMbrNo,comp member query member's info,the parameters 's info"
					+ "{memberNo:" + memberNo + "}");
		}
		ValidateUtil.checkMemberNo(memberNo);
		EnterpriseMember enterpriseMember;
		try 
		{
			enterpriseMember = enterpriseManageDao.queryEPMemberDetailByMemberNo(memberNo);
			if(enterpriseMember != null)
			{
				enterpriseMember.setPwd("");
			}
		} 
		catch (Exception e) 
		{
			logger.error("method:queryEnterpriseMemberByMbrNo","query enterprise by memberNo error",e);
			if(SQLException.class.isInstance(e.getCause()))
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"" + ((SQLException)(e.getCause())).getErrorCode(),e);
			}
			throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, "query db occur error", e);
		}
		
		if (logger.isDebugEnabled()) 
		{
			logger.debug("method:queryEnterpriseMemberByMbrNo,comp member query member's info successful!,the parameters 's info"
					+ "{memberNo:" + memberNo + "}");
		}
		return enterpriseMember;
	}

	@Override
	@Transactional(readOnly=true)
	public EnterpriseMember queryEnterpriseMemberInfo(String loginId, int loginType) throws MemberServiceException 
	{
		if (logger.isDebugEnabled()) 
		{
			logger.debug("method:queryEnterpriseMemberInfo,comp member query member's info,the parameters 's info"
					+ "{loginId:" + loginId + ",loginType:" + loginType + "}");
		}
		
		// 校验参数信息
		ValidateUtil.checkLoginType(loginId, loginType);
		
		EnterpriseMember enterpriseMember;
		try 
		{
			enterpriseMember = enterpriseManageDao.queryEPMemberDetailByLoginType(loginId,loginType);
			if(enterpriseMember != null)
			{
				enterpriseMember.setPwd("");
			}
		} 
		catch (Exception e)
		{
			logger.error("根据登入标识查询会员信息异常",e);
			if(SQLException.class.isInstance(e.getCause()))
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"" + ((SQLException)(e.getCause())).getErrorCode(),e);
			}
			throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, "查询数据库异常", e);
		}
		
		if (logger.isDebugEnabled()) 
		{
			logger.debug("method:queryEnterpriseMemberInfo,comp member query member's info successful,the parameters 's info"
					+ "{loginId:" + loginId + ",loginType:" + loginType + "}");
		}
		return enterpriseMember;
	}

	@Override
	@Transactional(rollbackFor= MemberServiceException.class,propagation=Propagation.REQUIRED)
	public EnterpriseMember loginEnterprise(String loginId, String password,int loginType) 
			throws MemberServiceException 
	{
		if (logger.isDebugEnabled()) 
		{
			logger.debug("method:loginEnterprise,enterprise member login ,the parameters 's info"
					+ "{loginId:" + loginId + ",password:" + password + ",loginType:" + loginType + "}");
		}
		
		// 校验参数信息
		ValidateUtil.checkLoginType(loginId, loginType);
		ValidateUtil.checkParamIsNull(password, "password");

		// 根据标示查询当前会员信息
		EnterpriseMember enterpriseMember = null;
		try 
		{
			Member member = memberManageDao.queryPersonBaseInfoByType(loginId,loginType,MemberType.COMP);
			BussineValidate.checkMemberStatus(member);
			
			//会员登录信息验证
			//第三次输入错误，需要提示****超过N次，请******
			Map<String ,Integer> map = memberHelpService.authMemberLogin(password, member.getMobile(),member.getEmail(),member.getLoginName(),MemberType.COMP);
			//member为false的时候,即账户密码不正确
			int tryTimes =  map.get("tryTimes");
			if(Constants.TRY_TIMES_3 == tryTimes)
			{
				throw new MemberServiceException(MemberResponseCode.BEYOND_MAX_LOGINFAIL_TIMES,"member's old password is wrong and beyond max try times");
			}
			else if(Constants.TRY_TIMES_2 == tryTimes)
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_PASSWORDIS_INVALID_SECOND,"second login fail");//第二次失败
			}
			else if(Constants.TRY_TIMES_1 == tryTimes)
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_PASSWORDIS_INVALID,"first login fail");//第一次失败
			}
			//查询企业扩展信息
			enterpriseMember = enterpriseManageDao.queryEnterpriseMemberByMemberNo(member.getMemberNo());
			if(enterpriseMember != null)
			{
				enterpriseMember.setPwd("");
			}
		} 
		catch (MemberServiceException e) 
		{
			logger.error("method:loginEnterprise,enterprise member login error ", e);
			throw e;
		}
		catch (Exception e) 
		{
			logger.error("method:loginEnterprise,enterprise member login error", e);
			if(SQLException.class.isInstance(e.getCause()))
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"" + ((SQLException)(e.getCause())).getErrorCode(),e);
			}
			throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"query data occur exception", e);
		}
		if (logger.isDebugEnabled()) 
		{
			logger.info("method:loginEnterprise,enterprise member login successful,the parameters 's info"	
					+ "{loginId:" + loginId + ",password:" + password + ",loginType:" + loginType + "}");
		}
		return enterpriseMember;
	}

	/**
	 * 增加操作员
	 */
	@Override
	@Transactional(rollbackFor= MemberServiceException.class,propagation=Propagation.REQUIRED)
	public void addOperator(MemberOperator operatorInfo) throws MemberServiceException 
	{
		if (logger.isDebugEnabled()) 
		{
			logger.info("method:addOperator,add enterprise member operator ,the parameters 's info"	
					+ "{operatorInfo:" + operatorInfo + "}");
		}
		ValidateUtil.checkObjectParamIsNull(operatorInfo, "operatorInfo");
		if(StringUtil.isStrNull(operatorInfo.getMobile()) 
				&& StringUtil.isStrNull(operatorInfo.getEmail())
				&& StringUtil.isStrNull(operatorInfo.getLoginName()))
		{
			throw new MemberServiceException(MemberResponseCode.INVALID_LEAST_ONE_VALUE,"the Parameter mobile, email, login name at least a parameter value");
		}
		try
		{
			//查看操作员是否已经被使用
			int counts = operatorManagerDao.queryOperatorIsExist(null,operatorInfo.getMobile(), operatorInfo.getEmail(),
					operatorInfo.getLoginName(),null,"",MemberType.COMP);
			if(counts != 0)
			{
				throw new MemberServiceException(MemberResponseCode.OPERATOR_HAS_REGISTER,
						"operator has exists : mobile: " + operatorInfo.getMobile()+
					" ,email: "	+ operatorInfo.getEmail()+ " ,loginName: " + operatorInfo.getLoginName());
			}
			
			OperatorInfo operInfo = new OperatorInfo();
			operInfo.setEmail(operatorInfo.getEmail());
			operInfo.setMemberNo(operatorInfo.getMemberNo());
			operInfo.setMobile(operatorInfo.getMobile());
			operInfo.setPwd(operatorInfo.getPwd());
			operInfo.setTelephone(operatorInfo.getTelephone());
			operInfo.setLoginName(operatorInfo.getLoginName());
			operInfo.setLockStatus(MemberLockStatus.NORMAL);
			operInfo.setOperatorType(operatorInfo.getOperatorType());
			operInfo.setStatus(OperatorStatus.YCHECK);
			operatorManagerDao.addOperatorInfo(operInfo);
		}
		catch (MemberServiceException e) 
		{
			logger.error("method:addOperator,add enterprise member operator error ", e);
			throw e;
		}
		catch (Exception e) 
		{
			logger.error("method:addOperator,add enterprise member operator error", e);
			if (SQLException.class.isInstance(e.getCause())) 
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, ""
								+ ((SQLException) e).getErrorCode(), e);
			} 
			throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, "update db occur exception",e);
		}
		if (logger.isDebugEnabled()) 
		{
			logger.info("method:addOperator,add enterprise member operator successful,the parameters 's info"	
					+ "{operatorInfo:" + operatorInfo + "}");
		}
	}

	@Override
	@Transactional(rollbackFor= MemberServiceException.class,propagation=Propagation.REQUIRED)
	public void updateOperator(MemberOperator operatorInfo) throws MemberServiceException 
	{
		if (logger.isDebugEnabled()) 
		{
			logger.info("method:updateOperator,update enterprise member operator,the parameters 's info"	
					+ "{operatorInfo:" + operatorInfo + "}");
		}
		try 
		{
			//查看当前操作员信息（根据操作员表ID）
			OperatorInfo currentOperatorInfo = operatorManagerDao.queryOperatorByID(operatorInfo.getOperatorId());
			if(currentOperatorInfo == null )
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_OPERATOR_NOT_EXISTS,"operator is not exists");
			}
			else if(currentOperatorInfo.getStatus() == OperatorStatus.CANCEL)
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_OPERATOR_STATUS_HAS_CANCEL,"operator has canceled");
			}
			//校验企业操作员信息是否已经使用
			Member midifyMember = new Member();
			midifyMember.setMemberType(MemberType.COMP);
			boolean modifyImportInfo = false;
			if (!StringUtil.isStrNull(operatorInfo.getMobile()) && !currentOperatorInfo.getMobile().equals(operatorInfo.getMobile())) 
			{
				modifyImportInfo = true;
				midifyMember.setMobile(operatorInfo.getMobile());
			}
			if (!StringUtil.isStrNull(operatorInfo.getEmail()) && !currentOperatorInfo.getEmail().equals(operatorInfo.getEmail()))
			{
				modifyImportInfo = true;
				midifyMember.setEmail(operatorInfo.getEmail());
			}
			if(!StringUtil.isStrNull(operatorInfo.getLoginName()) 
					&& !currentOperatorInfo.getLoginName().equals(operatorInfo.getLoginName())) 
			 {
				 modifyImportInfo = true;
				 midifyMember.setLoginName(operatorInfo.getLoginName()); 
			 }
			 //校验修改后的会员（手机，邮箱，登入名，证件类型+证件号码）是否已经存在
			if(modifyImportInfo)
			{
				memberHelpService.queryOperatorIsExist(midifyMember);
			}
			
			OperatorInfo operInfo = new OperatorInfo();
			operInfo.setOperatorId(operatorInfo.getOperatorId());
			operInfo.setEmail(operatorInfo.getEmail());
			operInfo.setMemberNo(operatorInfo.getMemberNo());
			operInfo.setMobile(operatorInfo.getMobile());
			operInfo.setPwd(operatorInfo.getPwd());
			operInfo.setTelephone(operatorInfo.getTelephone());
			operInfo.setLoginName(operatorInfo.getLoginName());
			operInfo.setLockStatus(operatorInfo.getLockStatus());
			operInfo.setOperatorType(operatorInfo.getOperatorType());
			operatorManagerDao.updateOperById(operInfo);
		} 
		catch (MemberServiceException e) 
		{
			logger.error("method:updateOperator,update enterprise member operator error ", e);
			throw e;
		}
		catch (Exception e) 
		{
			logger.error("method:updateOperator,update enterprise member operator error ", e);
			if (SQLException.class.isInstance(e.getCause())) 
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, ""
								+ ((SQLException) e).getErrorCode(), e);
			} 
			throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, "update db occur exception",e);
		}

		if (logger.isDebugEnabled()) 
		{
			logger.info("method:updateOperator,update enterprise member operator successful,the parameters 's info"	
					+ "{operatorInfo:" + operatorInfo + "}");
		}

	}

	@Override
	@Transactional(rollbackFor= MemberServiceException.class,propagation=Propagation.REQUIRED)
	public void cancelOperator(Long id) throws MemberServiceException 
	{
		if (logger.isDebugEnabled()) 
		{
			logger.info("method:cancelOperator,cancel enterprise member operator ,the parameters 's info"	
					+ "{id:" + id + "}");
		}
		try 
		{
			operatorManagerDao.cancelOperator(id);
		} 
		catch (Exception e) 
		{
			logger.error("method:cancelOperator,cancel enterprise member operator error ", e);
			if (SQLException.class.isInstance(e.getCause())) 
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, ""
								+ ((SQLException) e).getErrorCode(), e);
			} 
			throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, "update db occur error",e);
		}
		if (logger.isDebugEnabled()) 
		{
			logger.info("method:cancelOperator,cancel enterprise member operator successful,the parameters 's info"	
					+ "{id:" + id + "}");
		}
	}

	@Override
	@Transactional(readOnly=true)
	public List<MemberOperator> queryOperatorList(Long memberNo) throws MemberServiceException
	{
		logger.debug("会员号：" + memberNo);
		List<OperatorInfo> tempList = operatorManagerDao.queryOperatorList(memberNo);
		if (tempList != null && tempList.size() == 0) 
		{
			return null;
		}
		List<MemberOperator> operatorList = new ArrayList<MemberOperator>();
		for (OperatorInfo operatorInfo : tempList) 
		{
			MemberOperator operInfo = new MemberOperator();
			operInfo.setOperatorId(operatorInfo.getOperatorId());
			operInfo.setEmail(operatorInfo.getEmail());
			operInfo.setMemberNo(operatorInfo.getMemberNo());
			operInfo.setMobile(operatorInfo.getMobile());
			operInfo.setPwd(operatorInfo.getPwd());
			operInfo.setTelephone(operatorInfo.getTelephone());
			operInfo.setLoginName(operatorInfo.getLoginName());
			operInfo.setLockStatus(operatorInfo.getLockStatus());
			operInfo.setOperatorType(operatorInfo.getOperatorType());
			operatorList.add(operInfo);
		}
		tempList = null;
		return operatorList;
	}
	
	/**
	 * 企业会员开通本金账户
	 */
	@Override
	@Transactional(rollbackFor= MemberServiceException.class,propagation=Propagation.REQUIRED)
	public Long openNormalPrincipalAccount(Long memberNo, String productType, String subjectNo,
			String payPassword,Long overdraftLimitAmt) throws MemberServiceException 
	{
		if (logger.isDebugEnabled()) 
		{
			logger.info("method:openNormalPrincipalAccount,enterprise member open normal account,the parameters 's info"	
					+ "{memberNo:" + memberNo + ",productType:" + productType + ",payPassword:" + payPassword
					+ ",overdraftLimitAmt:"+  overdraftLimitAmt + "}");
		}
		// 1、参数合法性校验
		if (StringUtil.isObjectNull(memberNo) || StringUtil.isStrNull(productType)) 
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL, "parameter is null or empty");
		}
		// 会员信息校验
		EnterpriseMember enterpriseMember = validateMember(memberNo);
		// 2、生成资金账户开户请求参数
		if(StringUtil.isStrNull(payPassword)) 
		{
			// 获取登陆密码作为账户密码
			payPassword = enterpriseMember.getPwd();
		}
		OpenAccReturn openAccReturn  = null;
		// 3、调用账户系统开户
		try 
		{
			OpenAcc openAcc = AccountUtil.getDefaultAccount(memberNo, payPassword);
			openAcc.setSubjectNo(subjectNo);
			openAcc.setOverdraftAmountLimit(overdraftLimitAmt);
			// 调用账户开户，账户状态为未激活
			openAccReturn = acctProxyManageService.openAccount(openAcc);
			// 生成会员账户关联实体，并保存至数据库
			MemberAccount memberAccount = AccountUtil.makeMemberAccountFor101(openAccReturn.getAccountNo(), memberNo, productType, AcctUseFlag.DEFAULT);
			memberAccountManageDao.addMemberAccountInfo(memberAccount);
			//激活账户
			try
			{
				acctProxyManageService.makeAccountActive(openAccReturn.getAccountNo());
			}
			catch(Exception e)
			{
				logger.error("method:openNormalPrincipalAccount:makeAccountActive, active member's normal account active error", e);
			}
			
		} 
		catch (MemberServiceException e)
		{
			logger.error("method:openNormalPrincipalAccount, open normal account error", e);
			throw e;
		} 
		catch (Exception e) 
		{
			logger.error("method:openNormalPrincipalAccount, open normal account error", e);
			if(SQLException.class.isInstance(e.getCause()))
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"" + ((SQLException)(e.getCause())).getErrorCode(),e);
			}
			throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, "save db occur error", e);
		}

		if (logger.isDebugEnabled()) 
		{
			logger.info("method:openNormalPrincipalAccount,enterprise member open normal account successful,the parameters 's info"	
					+ "{memberNo:" + memberNo + ",productType:" + productType + ",payPassword:" + payPassword
					+ ",overdraftLimitAmt:"+  overdraftLimitAmt + "}");
		}
		return openAccReturn.getAccountNo();
	}

	/**
	 * 企业会员开通积分账户
	 */
	@Override
	@Transactional(rollbackFor= MemberServiceException.class,propagation=Propagation.REQUIRED)
	public Long openSFPAccount(Long memberNo, String productType, String payPassword) 
			throws MemberServiceException 
	{
		if (logger.isDebugEnabled()) 
		{
			logger.info("method:openSFPAccount,enterprise member open SF account,the parameters 's info"	
					+ "{memberNo:" + memberNo + ",productType:" + productType + ",payPassword:" + payPassword + "}");
		}
		// 1、参数合法性校验
		if (StringUtil.isObjectNull(memberNo) || StringUtil.isStrNull(productType)) 
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_COMMON_PARAM_ISNULL, "param is null or empty");
		}
		// 会员信息校验
		EnterpriseMember enterpriseMember = validateMember(memberNo);
		// 2、生成资金账户开户请求参数
		if(StringUtil.isStrNull(payPassword)) 
		{
			// 获取登陆密码作为账户密码
			payPassword = enterpriseMember.getPwd();
		}
		
		OpenAccReturn openAccReturn  = null;
		try 
		{
			OpenAcc openAcc = AccountUtil.getJFAccount(memberNo, payPassword);
			// 调用账户开户，账户状态为未激活
			// 3、调用账户系统开户
			openAccReturn = acctProxyManageService.openAccount(openAcc);
			// 生成会员账户关联实体，并保存至数据库
			MemberAccount memberAccount = AccountUtil.makeMemberAccountFor102(openAccReturn.getAccountNo(), memberNo, productType, AcctUseFlag.DEFAULT);
			memberAccountManageDao.addMemberAccountInfo(memberAccount);
			//激活账户
			try
			{
				acctProxyManageService.makeAccountActive(openAccReturn.getAccountNo());
			}
			catch(Exception e)
			{
				logger.error("method:openSFPAccount:makeAccountActive, active member's sfp account active error", e);
			}
		} 
		catch (MemberServiceException e) 
		{
			logger.error("method:openSFPAccount, open point account error", e);
			throw e;
		}
		catch (Exception e) 
		{
			logger.error("method:openSFPAccount, open point account error", e);
			if(SQLException.class.isInstance(e.getCause()))
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"" + ((SQLException)(e.getCause())).getErrorCode(),e);
			}
			throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, "save db occur error", e);
		}
		if (logger.isDebugEnabled()) 
		{
			logger.info("method:openSFPAccount,enterprise member open SF account successful,the parameters 's info"	
					+ "{memberNo:" + memberNo + ",productType:" + productType + ",payPassword:" + payPassword + "}");
		}
		return openAccReturn.getAccountNo();
	}
	
	/**
	 * 企业会员信息校验(校验会员是否存在)
	 * @param memberNo
	 * @throws MemberServiceException
	 */
	private EnterpriseMember validateMember(Long memberNo) throws MemberServiceException {
		// 会员信息校验
		EnterpriseMember enterpriseMember;
		try 
		{
			enterpriseMember = enterpriseManageDao.queryEPMemberDetailByMemberNo(memberNo);
		}
		catch (Exception e) 
		{
			logger.error("method:validateMember","query enterprise member by memberNo error",e);
			if(SQLException.class.isInstance(e))
			{				
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, ""+((SQLException)e).getErrorCode(), e);
			}
			else
			{
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, "query db occur error", e);
			}
		}
		if(null == enterpriseMember)
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_NOT_EXIST, "enterprise member is no exists");
		}
		return enterpriseMember;
	}
	
	/**
	 * 
	 *
	 * 方法说明：检查企业信息是否已经使用
	 *
	 * @param epMemberExt
	 * @param tmpMemberEx
	 * @param tmpMemberEx2
	 * @param hasChg
	 * @throws MemberServiceException 
	 */
	private void checkEpIsExists(EnterpriseMember epMemberExt,	EnterpriseMember tmpMemberEx) throws MemberServiceException
	{
		boolean hasChg = false;
		EnterpriseMember tmpMemberEx2 = new EnterpriseMember();
		if(tmpMemberEx == null)
		{
			throw new MemberServiceException(MemberResponseCode.MEMBER_NOT_EXIST,"Enterprise Member information is not exists");
		}
		
		//修改企业组织机构代码
		if(!StringUtil.isStrNull(epMemberExt.getEpORGCertNo()) && !epMemberExt.getEpORGCertNo().equals(tmpMemberEx.getEpORGCertNo()))
		{
			tmpMemberEx2.setEpORGCertNo(epMemberExt.getEpORGCertNo());
			hasChg = true;
		}
		//证件类型为其他，修改其他证件类型或者证件号
		if(epMemberExt.getEpCertType() != null && epMemberExt.getEpCertType().equals(tmpMemberEx.getEpCertType())
				&& epMemberExt.getEpCertType() == EPCertType.EP_OTHER)
		{
			if(!StringUtil.isStrNull(epMemberExt.getEpCertTypeOther()) 
					&& (!epMemberExt.getEpCertTypeOther().equals(tmpMemberEx.getEpCertTypeOther())
					|| !epMemberExt.getEpORGCertNo().equals(tmpMemberEx.getEpORGCertNo())))
			{
				tmpMemberEx2.setEpCertType(epMemberExt.getEpCertType());
				tmpMemberEx2.setEpCertTypeOther(epMemberExt.getEpCertTypeOther());
				tmpMemberEx2.setEpCertNo(epMemberExt.getEpCertNo());
				hasChg = true;
			}
		}
		//修改证件类型
		else if(epMemberExt.getEpCertType() != null && !epMemberExt.getEpCertType().equals(tmpMemberEx.getEpCertType()))
		{
			tmpMemberEx2.setEpCertType(epMemberExt.getEpCertType());
			tmpMemberEx2.setEpCertTypeOther(epMemberExt.getEpCertTypeOther());
			tmpMemberEx2.setEpCertNo(epMemberExt.getEpCertNo());
			hasChg = true;
		}
		//修改税务登记证
		else if(epMemberExt.getEpTaxRegNo() != null && !epMemberExt.getEpTaxRegNo().equals(tmpMemberEx.getEpTaxRegNo()))
		{
			tmpMemberEx2.setEpTaxRegNo(epMemberExt.getEpTaxRegNo());
			hasChg = true;
		}
		if(hasChg)
		{
			//查询修改后的值，是否满足
			int count = enterpriseManageDao.queryEPMemberIsExist(tmpMemberEx2);	
			if(count != 0)
			{
				throw new MemberServiceException(MemberResponseCode.MODIFY_MEMBER_AND_MEMBER_EXISTS,"Enterprise Member information is already in use when modify");
			}
		}
	}

	@Override
	public EnterpriseMember queryEnterpriseMember(EPCertType epCertType,
			String epCertTypeOther,String epCertNo) throws MemberServiceException
	{
		if (logger.isDebugEnabled()) 
		{
			logger.info("method:queryEnterpriseMember,query enterprise member,the parameters 's inf {" +
					"epCertType:" + epCertType + ",epCertTypeOther:" + epCertTypeOther + ",epCertNo:" + epCertNo + "}");
		}
		//参数校验
		ValidateUtil.checkObjectParamIsNull(epCertType,"certtype");
		if(EPCertType.EP_OTHER == epCertType)
		{
			ValidateUtil.checkParamIsNull(epCertTypeOther, "other certtype");
		}
		ValidateUtil.checkParamIsNull(epCertNo, "certno");
		
		EnterpriseMember enterpriseMember = null;
		try 
		{
			enterpriseMember = enterpriseManageDao.queryEnterpriseMemberInfo(epCertType,epCertTypeOther,epCertNo);
			if(enterpriseMember != null)
			{
				enterpriseMember.setPwd("");
			}
		} 
		catch (Exception e) 
		{
			logger.error("method:queryEnterpriseMember,query enterprise member error", e);
			if(SQLException.class.isInstance(e.getCause())){
				throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION,"" + ((SQLException)(e.getCause())).getErrorCode(),e);
			}
			throw new MemberServiceException(MemberResponseCode.MEMBER_DB_EXCEPTION, "query db occur exception", e);
		}
		
		if (logger.isDebugEnabled()) {
			logger.info("method:queryEnterpriseMember,query enterprise member successful!,the parameters 's info {" +
					"epCertType:" + epCertType + ",epCertTypeOther:" + epCertTypeOther + ",epCertNo:" + epCertNo + "}");
		}
		return enterpriseMember;
	}
}
